#include <stdio.h>
#include <stdlib.h>
#include "file_watcher.h"

void on_open(const std::string& file) {
    printf("open<%s>\n", file.c_str());
}

void on_close(const std::string& file) {
    printf("close<%s>\n", file.c_str());
}

void on_delete(const std::string& file) {
    printf("delete<%s>\n", file.c_str());
}

void on_change(const std::string& file) {
    printf("modify<%s>\n", file.c_str());
}

int main(int argc, const char **argv) {
    uv_loop_t *loop = uv_default_loop();
    if (!loop) return -1;

    file_watcher *fw = file_watcher::create(loop);
    if (!fw) return -1;

    fw->set_file_open_callback(on_open);
    fw->set_file_close_callback(on_close);
    fw->set_file_delete_callback(on_delete);
    fw->set_file_change_callback(on_change);

    int ret = fw->start();
    if (ret != 0) {
        perror("start");
        return ret;
    }

    ret = fw->watch("./a");
    if (ret != 0) {
        perror("watch");
        return ret;
    }

    uv_run(loop, UV_RUN_DEFAULT);
    return 0;
}
